<!DOCTYPE html >
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
 <link rel="stylesheet" href="../static/css/back/font.css">
 <link rel="stylesheet" href="../static/css/back/role.css">
    <link rel="stylesheet" href="../static/css/back/xadmin.css">
    <script type="text/javascript" src="../static/js/jquery-2.1.1.min.js"></script>
    
    <script type="text/javascript" src="../static/js/back/xadmin.js"></script>
    <script type="text/javascript">
    	console.log(getCookie('JSV'));
    	let js = '<script type="text/javascript" src="../static/js/back/goods-list.js?v='+getCookie('JSV')+'"><\/script>';
    	document.write(js);
    </script>
     
   
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
<style type="text/css">
.pace-goods {
	border: 1px #1e9fff solid;
	height: 110px;;
	width: 600px;
}
.pace-goods2 {
	width: 700px;
}
.pace-goods.spec {
margin-top: 10px;
	width: 700px !important;
}

.pace-title span {
	width: 85px;
	float: left;
	margin-left: 48px;
	margin-top: 15px;
}

.pace-title input {
	float: left;
	margin-left: 50px;
	margin-top: 15px;
	width: 85px;
}
.zhu-pic{
	width: 100px;
	height: 100px;
	border: 1px #efeef0 solid;
	    margin: 15px 0;
}
.zhu-pic img{
	width: 100%;
	height: 100%
}
.jianhao{
	    color: #fff;
    background-color: green;
    margin: 0 5px;
    border: 1px #fff solid;
    display: block;
    width: 20px;
    float: right;
    text-align: -webkit-center;
    border-radius: 27px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
        position: absolute;
    margin-left: 720px;
    margin-top: -81px;
}
.first-one{
	display: none;
}
</style>
</head>
  
  <body>
    <div class="x-body">
        <form action="" method="post" class="layui-form" lay-filter="formAdd" onsubmit="javascript:return false;">
       		<input type="hidden" name="id" value="" id="paramKey" />
       		<input type="hidden" name="shopId" value="" id="shopId" />
       		<div class="layui-form-item">
		      <label class="layui-form-label"><span class="x-red">*</span>商品分类</label>
		      <div class="layui-input-inline">
		        <select class="pIdsel" name="goodsTypeId" lay-verify="required" lay-search="">
		          <option value="">请选择分类</option>
		        </select>
		      </div>
		   </div>
		    <div class="layui-form-item">
			    <label class="layui-form-label">商品类型</label>
			    <div class="layui-input-block">
			      <input type="radio" name="goodsSupport" value="1" checked="" title="外卖"  lay-filter='gs'>
			      <input type="radio" name="goodsSupport" value="2" title="堂食"  lay-filter='gs'> 
			      <input type="radio" name="goodsSupport" value="1,2" title="外卖+堂食" lay-filter='gs'>
			    </div>
		  </div>
           <div class="layui-form-item">
               <label for="name" class="layui-form-label">
                   	排序
               </label>
               <div class="layui-input-inline">
                   <input type="text" id="sort" name="sort" required="" lay-verify=""
                   autocomplete="off" class="layui-input">
               </div>
           </div>
           <div class="layui-form-item">
               <label for="name" class="layui-form-label">
                   	<span class="x-red">*</span>商品名称
               </label>
               <div class="layui-input-inline">
                   <input type="text" id="title" name="goodsTitle" required="" lay-verify="required"
                   autocomplete="off" class="layui-input">
               </div>
           </div>
           <div class="layui-form-item">
               <label for="name" class="layui-form-label">
                   <span class="x-red">*</span> 商品主图
               </label>
               <input type="hidden" id="goodsPic" name="goodsPic" /> 
               <div class="layui-input-block">
                      <button type="button" class="layui-btn layui-btn-normal" onclick="choosePic()">图片库</button> 
                      <button type="button" class="layui-btn" id="up-btn-zhu"><i class="layui-icon"></i>本地图片</button> 
                      <div class="zhu-pic">
                      	<img alt="" src="">
                      </div>
               		  <button class="layui-btn" id="upload-btn2" ><i class="layui-icon"></i>确定上传</button>
               		  <span class="x-green"></span>
               </div>
           </div>
           <div class="layui-form-item">
               <label for="name" class="layui-form-label">
                   <span class="x-red">*</span> 商品图片
               </label>
               <input type="hidden" id="goodsPicArr" name="goodsPicArr" /> 
               <div class="layui-input-block">
                      <button type="button" class="layui-btn layui-btn-normal" onclick="choosePicArr()" >图片库</button> 
                      <button type="button" class="layui-btn" id="test2"><i class="layui-icon"></i>本地图片</button> 
					  <blockquote class="layui-elem-quote layui-quote-nm upload-img-preview" >
					    <xpre> 预览图：</xpre>
					    <div class="layui-upload-list" id="demo2"></div>
					 </blockquote>
<!--                		 <button class="layui-btn" id="upload-btn" ><i class="layui-icon"></i>确定上传</button> -->
               </div>
           </div>
           <div class="layui-form-item ">
               <label for="name" class="layui-form-label">&nbsp;
               </label>
               	<div class="layui-form-inline layui-word-aux">
				 	*上传商品图片，第一张图片将作为商品主图,支持同时上传多张图片；支持jpg、gif、png格式上传或从图片库中选择，
				 	建议使用尺寸800x800像素以上、大小不超过1M的正方形图片，上传后的图片将会自动保存在图片库的默认分类中。
				</div>
           </div>
           <div class="layui-form-item">
               <label for="name" class="layui-form-label">
                   <span class="x-red">*</span> 商品规格
               </label>
               <div class="speclist">
		               <div class="layui-input-block">
		                   <div class=" pace-goods">
		                   		<div class="pace-title">
		                   		<span style="    margin-left: 60px;" class="first-one">规格名称</span> 
		                   			<span>外卖价格(元)</span>
		                   			<span>堂食价格(元)</span>
		                   			<span><i class="x-red">*</i>库存</span>
		                   			<span>包装费</span>
		                   		</div>
		                   		<div class="pace-title">
		                   			<input type="hidden"  name="specids" />
		                   			<input type="text" id="first-one"    name="priceTitle1" required="" lay-verify=""  
				         		    autocomplete="off" class="layui-input first-one" value="">  
		                   			<input type="text" id="priceOut" name="priceOut1" required="" lay-verify="number"
		                   autocomplete="off" class="layui-input">
		                   			<input type="text" id="priceRoom" name="priceRoom1" required="" lay-verify=""
		                   autocomplete="off" class="layui-input">
		                   			<input type="text" id="goodsStock" name="goodsStock1" required="" lay-verify="number|required"
		                   autocomplete="off" class="layui-input">
		                   			<input type="text" id="goodsPackAmount" value="0" name="goodsPackAmount1" required="" lay-verify="number"
		                   autocomplete="off" class="layui-input">
		                   		</div>
		                   </div>
		                    
		               </div>
		           </div>
		            <div class="layui-form-item">
		            <br>
		           <label for="name" class="layui-form-label">
               	   </label>
		           <button class="layui-btn" onclick="addSpec()" >添加规格</button>
		           </div>
            </div>
           <div class="layui-form-item">
               <label for="name" class="layui-form-label">
                  限购(份)
               </label>
               <div class="layui-input-inline">
                   <input type="text" id="goodsLimitBuy" name="goodsLimitBuy" required="" lay-verify=""
                   autocomplete="off" class="layui-input">
               </div>
           </div>
            <div class="layui-form-item ">
               <label for="name" class="layui-form-label"></label>
               	<div class="layui-form-inline layui-word-aux">
				 	*设置商品每单只能买多少份(仅限单规格商品)
				</div>
           </div>
           <div class="layui-form-item">
               <label for="name" class="layui-form-label">
                  起售(份)
               </label>
               <div class="layui-input-inline">
                   <input type="text" id="goodsStartAt" name="goodsStartAt" required="" lay-verify=""
                   autocomplete="off" class="layui-input">
               </div>
           </div>
			<div class="layui-form-item ">
               <label for="name" class="layui-form-label"></label>
               	<div class="layui-form-inline layui-word-aux">
				 	*设置商品至少多少份起售(仅限单规格商品)
				</div>
           </div>
		   <div class="layui-form-item">
				<label class="layui-form-label">商品描述</label>
				<div class="layui-input-block">
					<input type="text" name="goodsTitleSimple" lay-verify=""
						autocomplete="off" class="layui-input">
				</div>
			</div>
		   <div class="layui-form-item">
				<label class="layui-form-label">商品详情</label>
				<div class="layui-input-block">
					<textarea class="layui-textarea" id="LAY_demo1" name="goodsDetail" style="display: none" placeholder="请输入提现须知"></textarea>
				</div>
			</div>
		  <div class="layui-form-item isshangjia">
			    <label class="layui-form-label">是否上架</label>
			    <div class="layui-input-block">
			      <input type="radio" name="status" value="1" checked="" title="上架"  lay-filter='stat'>
			      <input type="radio" name="status" value="2" title="下架" lay-filter='stat'>
			    </div>
		  </div>
		   
			<div class="layui-form-item">
			<label class="layui-form-label"></label>
               		 <button class="layui-btn" lay-submit="" id="upload-btn" lay-filter="add">确定</button>
               		 <button class="layui-btn" onclick="x_admin_close()">取消</button>
              	</div>
            </form>
    </div>
    <script>
    _showData = {};
    var uploaddata={};
    var files ;
    var returnjia = 1;
    var form = null;
        layui.use(['form','layer' ,'layedit','upload'], function(){
            $ = layui.jquery,
         form = layui.form,
         layedit = layui.layedit
         ,upload = layui.upload
          ,layer = layui.layer;
        
         layedit.set({
       	  uploadImage: {
       	    url: '../sys/upload/layeditUploadPics?spid='+spid //接口url
       	    ,type: 'post' //默认post,
       	    
       	  }
       	});
        //构建一个默认的编辑器
        var index = layedit.build('LAY_demo1');
        
          //自定义验证规则
          form.verify({
            nikename: function(value){
              if(value.length < 5){
                return '昵称至少得5个字符啊';
              }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
          });
          form.on('radio(go)', function(data){
        	  console.log(data.value); //被点击的radio的value值
        	  if(data.value == 1){
        		  $('input[name="priceOut"]').attr('lay-verify','number');
        		  $('input[name="priceRoom"]').attr('lay-verify','');
        	  }else if(data.value == 2){
        		  $('input[name="priceOut"]').attr('lay-verify','');
        		  $('input[name="priceRoom"]').attr('lay-verify','number');
        	  }else{
        		  $('input[name="priceOut"]').attr('lay-verify','number');
        		  $('input[name="priceRoom"]').attr('lay-verify','number');
        	  }
        	}); 
          
         
          
          //监听提交
          form.on('submit(add)', function(data){
        	  console.log(data);
//         	  return;
        	var content = layedit.getContent(index);
			data.field.goodsDetail = content;
			if(data.field.priceOut){
				data.field.priceOut = (data.field.priceOut * 100).toFixed(0)
			}
			if(data.field.priceRoom){
				data.field.priceRoom = (data.field.priceRoom * 100).toFixed(0)
			}
			if(data.field.goodsPackAmount){
				data.field.goodsPackAmount = (data.field.goodsPackAmount * 100).toFixed(0)
			}
            console.log(data.field);
            uploaddata =data.field ;
            var specids = "";
            var spectits = "";
            var specouts = "";
            var specromss = "";
            var speckucs = "";
            var specbzs = "";
     		var specTil = $('input[name="priceTitle1"]');
     			console.log(specTil);
     		for (var i = 0; i < specTil.length; i++) {
     			var sp = specTil[i];
     			console.log($(sp).val());
     			//ids
     			var iids = ($('input[name="specids"]').eq(i)).val();
     			if(!iids){
     				iids = 0;
     			}
     			specids += iids;
     			//out
     			var outs = ($('input[name="priceOut1"]').eq(i)).val();
     			if(!outs){
     				outs = 0;
     			}
     			specouts += (outs * 100).toFixed(0);
     			//room
     			var roms = ($('input[name="priceRoom1"]').eq(i)).val();
     			if(!roms){
     				roms = 0;
     			}
     			specromss +=  (roms * 100).toFixed(0);
     			//kucun
     			var kucs = ($('input[name="goodsStock1"]').eq(i)).val();
     			if(!kucs){
     				kucs = 0;
     			}
     			speckucs += kucs;
     			//baozhuang
     			var bzs = ($('input[name="goodsPackAmount1"]').eq(i)).val();
     			if(!bzs){
     				bzs = 0;
     			}
     			specbzs +=   (bzs * 100).toFixed(0);
     			//title
     			var ttils =$(sp).val();
     			if(!ttils){
     				ttils=0;
     			}
     			spectits += ttils;
     			
     			
     			if(i+1 != specTil.length){
     				specids +="-";
     				spectits +="-";
     				specromss +="-";
     				speckucs +="-";
     				specbzs +="-";
     				specouts +="-";
     			}
			}
     		uploaddata['specids'] = specids;
     		uploaddata['spectits'] = spectits;
     		uploaddata['specromss'] = specromss;
     		uploaddata['speckucs'] = speckucs;
     		uploaddata['specbzs'] = specbzs;
     		uploaddata['specouts'] = specouts;
     		
     		
            updateInfo(uploaddata);
            return false;
          });
          form.on('radio(stat)', function(data){
          		console.log(data.value);
          }); 
//           _ddd['title']="eeiie";
//           _ddd['goodsSupport']='1,2';
		  
          
          var t1=window.setInterval(showData, 200);
          var ti_show_dd = 0;
			function showData(){
				ti_show_dd++;
		    	console.log(_showData);
				if (_showData) {
					$("#LAY_demo1").val(_showData.goodsDetail);
			          index = layedit.build('LAY_demo1');
					$('.zhu-pic img').attr('src',_showData.goodsPic);
		        	  var div ="";
		        	  if(_showData.goodsPicArr){
		        		  var pararr = _showData.goodsPicArr.split(',');
		        		  for (var i = 0; i < pararr.length; i++) {
		        			 var arpi = pararr[i];
		        			 console.log(arpi);
		        			 div += '<div id="upload-' + i + '" class="refund-img-item exist"><img class="proimg" src="' + arpi + '"><img src="../static/images/back/close.png" title="移除" class="refund-img-close"></div>';
						}
		        		  $('#demo2').before(div);
		        	  }
		        	  if(_showData.status === 4){
		        		  $('.isshangjia').hide();
		        	  }
				    window.clearInterval(t1); 
				    if(_showData.specList){
		        		  var los =  _showData.specList;
		        		  var htmls = "";
		        		  for (var i = 0; i < los.length; i++) {
		        			var ls =   los[i];
							console.log(los[i]);
							
							if(i==0){
								$('input[name="priceOut1"]').val((ls.priceOut /100 ).toFixed(2));
								$('input[name="specids"]').val(ls.id);
								$('input[name="priceTitle1"]').val(ls.title);
								$('input[name="goodsStock1"]').val(ls.goodsStock);
								$('input[name="priceRoom1"]').val((ls.priceRoom /100 ).toFixed(2));
								$('input[name="goodsPackAmount1"]').val((ls.goodsPackAmount /100 ).toFixed(2));
								form.render();
								continue;
							}
							
							 htmls = '<div class="layui-input-block">                                                                               '
							          +'         <div class=" pace-goods spec">                                                                        '
					               	+'	<div class="pace-title">                                                                                       '
					               	+'		<span style="    margin-left: 60px;">规格名称</span>                                                                                      '
					               	+'		<span>外卖价格(元)</span>                                                                                  '
					               	+'		<span>堂食价格(元)</span>                                                                                  '
					               	+'		<span><i class="x-red">*</i>库存</span>                                                                    '
					               	+'		<span>包装费</span>                                                                                        '
					               	+'	</div>                                                                                                         '
					               	+'	<div class="pace-title">                                                                                       '
					               	+'<input type="hidden" name="specids" value="'+ls.id+'" />'
					               	+'		<input type="text" id=""  name="priceTitle1" required="" lay-verify="required"                          '
							          +'     autocomplete="off" class="layui-input" value="'+ls.title+'">                                                                   '
							          +'     			<input type="text" id="" name="priceOut1" required="" lay-verify=""              '
							          +'     autocomplete="off" class="layui-input" value="'+(ls.priceOut /100 ).toFixed(2)+'">                                                                   '
							          +'     			<input type="text" id="" name="priceRoom1" required="" lay-verify=""                  '
							          +'     autocomplete="off" class="layui-input" value="'+(ls.priceRoom /100 ).toFixed(2)+'">                                                                    '
							          +'     			<input type="text" id="" name="goodsStock1" required="" lay-verify="number|required" '
							          +'     autocomplete="off" class="layui-input" value="'+ls.goodsStock+'">                                                                   '
							          +'     			<input type="text" id="" name="goodsPackAmount1" required="" lay-verify="number"'
							          +'     autocomplete="off" class="layui-input" value="'+(ls.goodsPackAmount /100 ).toFixed(2)+'">                                                                   '
							          +'     		</div>                                                                                             '
							          +'     </div>'
							          +'  <div class="layui-form-mid layui-word-aux ">'
							          +'  	<span class="jianhao"  onclick="removeSpec(this)">-</span>'
							          +'  </div>'
							          +' </div>';
							$('.speclist').append(htmls);
							form.render();
							var dd = $('.pace-goods.spec');
							if(dd.length == 0){
				        		$('.speclist').eq(0).find('.pace-goods').removeClass('pace-goods2');
				        		$('.first-one').hide();
				        	}else{
				        		$('.speclist').eq(0).find('.pace-goods').addClass('pace-goods2');
				        		$('.first-one').show();
				        	}
							form.render();
						}
		        	  }
		        	  
		          }
					form.val("formAdd", _showData);
					form.render(); 
				}
				if(ti_show_dd>=120){
					window.clearInterval(t1); 
				}
          
          //关于上传
        //多图片上传
         uploadListIns  =  upload.render({
            elem: '#test2',
            url: '../sys/upload/uploadPics',
            auto: true,
            multiple: true,
//             number: 3,//允许上传的数量
//             bindAction: '#upload-btn',//指向一个按钮触发上传 
//             size:'2048',//尺寸
            accept: "images",//指定允许上传时校验的文件类型
            acceptMime:'image/*',//只显示图片文件
            exts:"jpg|png|gif|jpeg",//允许后缀
            drag:"false",//是否文件拖拽上传
            data:{spid:spid},//上传接口的额外参数
            choose: function(obj) { //选择文件后的回调函数
            	  files = this.files = obj.pushFile(); 
                  console.log(files);
                  obj.preview(function(index, file, result){
//                       $('#demo2').append('<img wdith=50 height=50 src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                      //obj.upload(index, file); //对上传失败的单个文件重新上传，一般在某个事件中使用
                      var div = $(['<div id="upload-' + index + '" class="refund-img-item exist">', '<img class="proimg" src="' + result + '">',          '<img src="../static/images/back/close.png" title="移除" class="refund-img-close">', '</div>'].join(''));
                      //删除列表中对应的文件
//                       div.find('.refund-img-close').on('click', function() {
//                     	  console.log(index); 
//                           delete files[index]; //删除对应的文件
//                           div.remove();
//                           removePicArR(obj,index);
//                           uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
//                       });
                      $('#demo2').before(div);
                      form.render();
                      delete files[index];
                    });
              }
            ,before: function(obj){
            	layer.load();
            }
            ,done: function(res){
              //上传完毕
              if($("#goodsPicArr").val()){
	              $("#goodsPicArr").val($("#goodsPicArr").val()+","+res.returnObject)
              }else{
            	  $("#goodsPicArr").val(res.returnObject)
              }
             /*  console.log(Object.keys(files).length);
              
              console.log(returnjia +"+"+ Object.keys(files).length);
              if(returnjia == Object.keys(files).length){
            	  console.log('开始执行修改操作');
              //updateInfo(data.field);
              }else{
            	  returnjia++;
              } */
              
            }
            ,error:function(obj){
            	console.log(obj);
            	layer.closeAll('loading'); //关闭loading
            }
            ,allDone: function(obj){ //当文件全部被提交后，才触发
            	 layer.closeAll('loading'); //关闭loading
            	/*  var picarr = "";
            	 if($("#goodsPicArr").val()){
	            	var srr =  $("#goodsPicArr").val().split(',');
            		 for (var i = 0; i < srr.length; i++) {
						if(srr[i]){
							picarr+=srr[i];
						}else{
							continue;
						}
						if((i+1) != srr.length){
							picarr+=",";
						}
					}
            	 }
            	console.log(picarr);
            	uploaddata['goodsPicArr'] = picarr;
            	var specData = "";
         		var specTil = $('input[name="priceTitle1"]');
         			console.log(specTil);
         		for (var i = 0; i < specTil.length; i++) {
         			var sp = specTil[i];
         			console.log($(sp).val());
				}
         		
         		var content = layedit.getContent(index);
         		uploaddata.goodsDetail = content;
    			if(uploaddata.priceOut){
    				uploaddata.priceOut = (uploaddata.priceOut * 100).toFixed(0)
    			}
    			if(uploaddata.priceRoom){
    				uploaddata.priceRoom = (uploaddata.priceRoom * 100).toFixed(0)
    			}
    			if(uploaddata.goodsPackAmount){
    				uploaddata.goodsPackAmount = (uploaddata.goodsPackAmount * 100).toFixed(0)
    			}
         		//
         		 var specids = "";
                 var spectits = "";
                 var specouts = "";
                 var specromss = "";
                 var speckucs = "";
                 var specbzs = "";
          		var specTil = $('input[name="priceTitle1"]');
          			console.log(specTil);
          		for (var i = 0; i < specTil.length; i++) {
          			var sp = specTil[i];
          			console.log($(sp).val());
          			//ids
          			var iids = ($('input[name="specids"]').eq(i)).val();
          			if(!iids){
          				iids = 0;
          			}
          			specids += iids;
          			//out
          			var outs = ($('input[name="priceOut1"]').eq(i)).val();
          			if(!outs){
          				outs = 0;
          			}
          			specouts += (outs * 100).toFixed(0);
          			//room
          			var roms = ($('input[name="priceRoom1"]').eq(i)).val();
          			if(!roms){
          				roms = 0;
          			}
          			specromss +=  (roms * 100).toFixed(0);
          			//kucun
          			var kucs = ($('input[name="goodsStock1"]').eq(i)).val();
          			if(!kucs){
          				kucs = 0;
          			}
          			speckucs += kucs;
          			//baozhuang
          			var bzs = ($('input[name="goodsPackAmount1"]').eq(i)).val();
          			if(!bzs){
          				bzs = 0;
          			}
          			specbzs +=   (bzs * 100).toFixed(0);
          			//title
          			var ttils =$(sp).val();
          			if(!ttils){
          				ttils=0;
          			}
          			spectits += ttils;
          			
          			
          			if(i+1 != specTil.length){
          				specids +="-";
          				spectits +="-";
          				specromss +="-";
          				speckucs +="-";
          				specbzs +="-";
          				specouts +="-";
          			}
     			}
          		uploaddata['specids'] = specids;
          		uploaddata['spectits'] = spectits;
          		uploaddata['specromss'] = specromss;
          		uploaddata['speckucs'] = speckucs;
          		uploaddata['specbzs'] = specbzs;
          		uploaddata['specouts'] = specouts;
          		
//      return;
                updateInfo(uploaddata);*/
            	 form.render();
              } 
          });
        //多图片上传
         uploadListIns2  =  upload.render({
            elem: '#up-btn-zhu',
            url: '../sys/upload/uploadPics',
            auto: false,
            multiple: false,
//             number: 3,//允许上传的数量
            bindAction: '#upload-btn2',//指向一个按钮触发上传 
            size:'2048',//尺寸
            accept: "images",//指定允许上传时校验的文件类型
            acceptMime:'image/*',//只显示图片文件
            exts:"jpg|png|gif|jpeg",//允许后缀
            drag:"false",//是否文件拖拽上传
            data:{spid:spid},//上传接口的额外参数
            choose: function(obj) { //选择文件后的回调函数
                  obj.preview(function(index, file, result){
                      $('.zhu-pic img').attr("src",result);
                    });
              }
            ,before: function(obj){
            	layer.load();
            }
            ,done: function(res){
            	 layer.closeAll('loading'); //关闭loading
            	  $('.x-green').text('上传成功。');
	              $("#goodsPic").val(res.returnObject)
            }
          });
        });
        
        $(function(){
        	$("body").on('click','.refund-img-close',function(){
        		console.log($(".refund-img-close").index(this));
            	var ind = $(".refund-img-close").index(this);
            	var arr2 =[];
//             	console.log($("#goodsPicArr").val());
            	if($("#goodsPicArr").val()){
	            	var arr =  $("#goodsPicArr").val().split(',');
	            	console.log(arr);
	            	for (var i = 0; i < arr.length; i++) {
	            		console.log(ind+"-"+i);
						if(ind != i){
							arr2.push(arr[i]);
						}else{
							//arr2 +="";
						}
// 						if(ind != 0 &&(i+1) != arr.length){
// 							arr2+=',';
// 						}
					}
            	}
            	$("#goodsPicArr").val(arr2.join(','));
            	$(this).parent().remove(); 
            })
        })
        function addSpec(){
        	var htmls ='<div class="layui-input-block">                                                                               '
				          +'         <div class=" pace-goods spec">                                                                        '
		               	+'	<div class="pace-title">                                                                                       '
		               	+'		<span style="    margin-left: 40px;" >规格名称</span>                                                                                      '
		               	+'		<span>外卖价格(元)</span>                                                                                  '
		               	+'		<span>堂食价格(元)</span>                                                                                  '
		               	+'		<span><i class="x-red">*</i>库存</span>                                                                    '
		               	+'		<span>包装费</span>                                                                                        '
		               	+'	</div>                                                                                                         '
		               	+'	<div class="pace-title">                                                                                       '
		               	+'<input type="hidden" name="specids" value="" />'
		               	+'		<input type="text" id=""  name="priceTitle1" required="" lay-verify="required"                          '
				          +'     autocomplete="off" class="layui-input" value="">                                                                   '
				          +'     			<input type="text" id="" name="priceOut1" required="" lay-verify=""              '
				          +'     autocomplete="off" class="layui-input" value="">                                                                   '
				          +'     			<input type="text" id="" name="priceRoom1" required="" lay-verify=""                  '
				          +'     autocomplete="off" class="layui-input" value="">                                                                    '
				          +'     			<input type="text" id="" name="goodsStock1" required="" lay-verify="number|required" '
				          +'     autocomplete="off" class="layui-input" value="">                                                                   '
				          +'     			<input type="text" id="" name="goodsPackAmount1" required="" lay-verify="number"'
				          +'     autocomplete="off" class="layui-input" value="">                                                                   '
				          +'     		</div>                                                                                             '
				          +'     </div>'
				          +'  <div class="layui-form-mid layui-word-aux ">'
				          +'  	<span class="jianhao" onclick="removeSpec(this)">-</span>'
				          +'  </div>'
				          +' </div>';
				$('.speclist').append(htmls);
				$('.pace-goods.spec').eq(0).find('span').eq(0).attr('style','margin-left: 60px;');
				var dd = $('.pace-goods.spec');
				if(dd.length == 0){
	        		$('.speclist').eq(0).find('.pace-goods').removeClass('pace-goods2');
	        		$('.first-one').hide();
	        	}else{
	        		$('.speclist').eq(0).find('.pace-goods').addClass('pace-goods2');
	        		$('.first-one').show();
	        	}
				form.render();
        }
        function removeSpec(obj){
        	$(obj).parent().parent().remove();
        	var dd = $('.pace-goods.spec');
        	console.log(dd.length);
        	if(dd.length == 0){
        		$('.speclist').eq(0).find('.pace-goods').removeClass('pace-goods2');
        		$('.first-one').hide();
        	}else{
        		$('.speclist').eq(0).find('.pace-goods').addClass('pace-goods2');
        		$('.first-one').show();
        	}
        	
        }
        var _chooseType = 1;
        //打开图片库
        function choosePic(){
        	_chooseType = 1;
      	  x_admin_show('选择图库','./goods~goods-pic.html?type=choose','','',true);
        }
        function choosePicArr(){
        	_chooseType = 2;
      	  x_admin_show('选择图库','./goods~goods-pic.html?type=choose','','',true);
        }
        function returnChoose(pic){
        	if(_chooseType == 1){
        		$(".zhu-pic img").attr("src",pic[0]);
        		$("#goodsPic").val(pic[0]);
        	}else if(_chooseType == 2){
        		var div= '';
        		var pararr = pic;
      		  	for (var i = 0; i < pararr.length; i++) {
	      			 var arpi = pararr[i];
	      			 div += '<div id="upload-' + i + '" class="refund-img-item exist"><img class="proimg" src="' + arpi + '"><img src="../static/images/back/close.png" title="移除" class="refund-img-close"></div>';
				}
      		    $('#demo2').before(div);
      		    if( $("#goodsPicArr").val()){
      		    	 $("#goodsPicArr").val($("#goodsPicArr").val()+","+pic.join(","));
      		    }else{
	      		    $("#goodsPicArr").val(pic.join(","));
      		    }
        	}
        	form.render();
        }
    </script>

  </body>

</html>